<!DOCTYPE html>
<html>

<head>
    <title>Adaptive Learning App Demo</title>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
      var APIKey = "DxN1BjoFMCVcKrewTTKBP";
      var APIDomain = "https://ivle.nus.edu.sg/";
      var APIUrl = APIDomain + "api/lapi.svc/";
      var LoginURL = APIDomain + "api/login/?apikey=" + APIKey + "&url=http%3A%2F%2Flocalhost%2Fadaptive_learning%2Findex.html";

      var myModuleInfo = null;

      //function to get the query string parameters
      var search = function () {
          var p = window.location.search.substr(1).split(/\&/), l = p.length, kv, r = {};
          while (l--) {
              kv = p[l].split(/\=/);
              r[kv[0]] = kv[1] || true; //if no =value just set it as true
          }
          return r;
      } ();


      //variable to store the Authentication Token
      var Token = "";

      //check query string for search token
      if (search.token && search.token.length > 0 && search.token != 'undefined') {
          Token = search.token;
      }

      $(document).ready(function () {
          if (Token.length < 1) {
              window.location = LoginURL;
          }
          else {
              //$('#lbl_Token').html(Token);
              Populate_UserName();
              Populate_UserID();
          }
      });

      function Populate_UserName() {
          var url = APIUrl + "UserName_Get?output=json&callback=?&APIKey=" + APIKey + "&Token=" + Token;
          $('#dbg_UserInfo').append("<span>Request: " + url + "</span><br />");

          jQuery.getJSON(url, function (data) {
              $('#lbl_Name').html(data);
              $('#dbg_UserInfo').append("<span>Response: " + data + "</span>");
        $.post( "login.html", { name: data});
          });
      }
    
      function Populate_UserID() {
            var url = APIUrl + "UserID_Get?output=json&callback=?&APIKey=" + APIKey + "&Token=" + Token;
            $('#dbg_UserID').append("<span>Request: " + url + "</span><br />");

            jQuery.getJSON(url, function (data) {
                $('#lbl_ID').html(data);
                $('#dbg_UserID').append("<span>Response: " + data + "</span>");
            });
        }
    </script>
</head>

<body>
    <b id="welcome_message"></b>
    <b>Welcome <span id="lbl_Name"><img src="http://ivle.nus.edu.sg/images/spinner.gif"/></span></b>
</body>

</html>
